<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>雷电风险评估工具</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
            color: #333;
        }
        .container {
            max-width: 900px;
            margin: 0 auto;
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }
        h2 {
            color: #2980b9;
            margin-top: 25px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        input[type="number"], select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 16px;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 20px;
            font-size: 16px;
            cursor: pointer;
            border-radius: 4px;
            display: block;
            margin: 30px auto;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #2980b9;
        }
        .result-section {
            margin-top: 40px;
            padding: 20px;
            background-color: #f9f9f9;
            border-radius: 5px;
            border-left: 5px solid #3498db;
        }
        .risk-level {
            font-size: 24px;
            font-weight: bold;
            text-align: center;
            padding: 15px;
            margin-top: 20px;
            border-radius: 5px;
        }
        .low-risk {
            background-color: #d4edda;
            color: #155724;
            border: 2px solid #c3e6cb;
        }
        .medium-risk {
            background-color: #fff3cd;
            color: #856404;
            border: 2px solid #ffeeba;
        }
        .high-risk {
            background-color: #f8d7da;
            color: #721c24;
            border: 2px solid #f5c6cb;
        }
        .info-icon {
            color: #3498db;
            cursor: help;
            margin-left: 5px;
        }
        .tooltip {
            position: relative;
            display: inline-block;
        }
        .tooltip .tooltiptext {
            visibility: hidden;
            width: 200px;
            background-color: #555;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 5px;
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            margin-left: -100px;
            opacity: 0;
            transition: opacity 0.3s;
            font-size: 14px;
            font-weight: normal;
        }
        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>雷电风险评估工具</h1>
        
        <form id="lightningRiskForm">
            <h2>1. 建筑物基本信息</h2>
            <div class="form-group">
                <label for="buildingType">建筑物类型:</label>
                <select id="buildingType" required>
                    <option value="">-- 请选择 --</option>
                    <option value="residential">住宅建筑</option>
                    <option value="office">办公楼</option>
                    <option value="industrial">工业建筑</option>
                    <option value="hospital">医院/紧急服务设施</option>
                    <option value="school">学校</option>
                    <option value="cultural">文化/历史建筑</option>
                    <option value="other">其他</option>
                </select>
            </div>
            
            <div class="form-group">
                <label for="buildingHeight">建筑物高度 (米):</label>
                <input type="number" id="buildingHeight" min="0" step="0.1" required>
            </div>
            
            <div class="form-group">
                <label for="buildingArea">建筑物占地面积 (平方米):</label>
                <input type="number" id="buildingArea" min="0" step="1" required>
            </div>
            
            <h2>2. 地理位置信息</h2>
            <div class="form-group">
                <label for="lightningDensity">当地雷暴日数 (天/年):</label>
                <input type="number" id="lightningDensity" min="0" max="365" required>
            </div>
            
            <div class="form-group">
                <label for="terrainType">地形类型:</label>
                <select id="terrainType" required>
                    <option value="">-- 请选择 --</option>
                    <option value="flat">平坦地形</option>
                    <option value="hill">丘陵</option>
                    <option value="mountain">山地</option>
                    <option value="water">水域/湖泊附近</option>
                    <option value="urban">城市密集区</option>
                </select>
            </div>
            
            <h2>3. 建筑物特性</h2>
            <div class="form-group">
                <label for="structureMaterial">主要结构材料:</label>
                <select id="structureMaterial" required>
                    <option value="">-- 请选择 --</option>
                    <option value="concrete">钢筋混凝土</option>
                    <option value="steel">钢结构</option>
                    <option value="wood">木结构</option>
                    <option value="brick">砖混结构</option>
                </select>
            </div>
            
            <div class="form-group">
                <label for="roofMaterial">屋顶材料:</label>
                <select id="roofMaterial" required>
                    <option value="">-- 请选择 --</option>
                    <option value="metal">金属</option>
                    <option value="tile">瓦片</option>
                    <option value="concrete">混凝土</option>
                    <option value="asphalt">沥青</option>
                    <option value="wood">木质</option>
                </select>
            </div>
            
            <div class="form-group">
                <label for="hasLightningRod">是否安装避雷针系统:</label>
                <select id="hasLightningRod" required>
                    <option value="">-- 请选择 --</option>
                    <option value="yes">是</option>
                    <option value="no">否</option>
                </select>
            </div>
            
            <div class="form-group">
                <label for="hasSurgeProtection">是否安装电涌保护装置:</label>
                <select id="hasSurgeProtection" required>
                    <option value="">-- 请选择 --</option>
                    <option value="yes">是</option>
                    <option value="no">否</option>
                </select>
            </div>
            
            <h2>4. 内部风险因素</h2>
            <div class="form-group">
                <label for="occupantDensity">人员密度 (人/平方米):</label>
                <input type="number" id="occupantDensity" min="0" step="0.01" required>
            </div>
            
            <div class="form-group">
                <label for="flammableMaterials">建筑物内易燃材料数量:</label>
                <select id="flammableMaterials" required>
                    <option value="">-- 请选择 --</option>
                    <option value="none">无</option>
                    <option value="low">少量</option>
                    <option value="medium">中等</option>
                    <option value="high">大量</option>
                </select>
            </div>
            
            <div class="form-group">
                <label for="electronicEquipment">贵重电子设备价值 (万元):</label>
                <input type="number" id="electronicEquipment" min="0" step="1" value="0" required>
            </div>
            
            <button type="button" onclick="calculateRisk()">计算雷电风险</button>
        </form>
        
        <div id="resultSection" class="result-section" style="display: none;">
            <h2>风险评估结果</h2>
            <div id="riskLevel" class="risk-level"></div>
            
            <h3>风险因素分析</h3>
            <table>
                <tr>
                    <th>风险因素</th>
                    <th>权重</th>
                    <th>得分</th>
                </tr>
                <tbody id="riskFactorsTable">
                </tbody>
            </table>
            
            <h3>防护建议</h3>
            <div id="protectionAdvice"></div>
        </div>
    </div>

    <script>
        function calculateRisk() {
            // 获取输入值
            const buildingType = document.getElementById('buildingType').value;
            const buildingHeight = parseFloat(document.getElementById('buildingHeight').value);
            const buildingArea = parseFloat(document.getElementById('buildingArea').value);
            const lightningDensity = parseInt(document.getElementById('lightningDensity').value);
            const terrainType = document.getElementById('terrainType').value;
            const structureMaterial = document.getElementById('structureMaterial').value;
            const roofMaterial = document.getElementById('roofMaterial').value;
            const hasLightningRod = document.getElementById('hasLightningRod').value;
            const hasSurgeProtection = document.getElementById('hasSurgeProtection').value;
            const occupantDensity = parseFloat(document.getElementById('occupantDensity').value);
            const flammableMaterials = document.getElementById('flammableMaterials').value;
            const electronicEquipment = parseFloat(document.getElementById('electronicEquipment').value);
            
            // 验证输入
            if (!buildingType || isNaN(buildingHeight) || isNaN(buildingArea) || isNaN(lightningDensity) || 
                !terrainType || !structureMaterial || !roofMaterial || !hasLightningRod || 
                !hasSurgeProtection || isNaN(occupantDensity) || !flammableMaterials || isNaN(electronicEquipment)) {
                alert('请填写所有必填字段！');
                return;
            }
            
            // 计算各项风险得分
            let totalScore = 0;
            const riskFactors = [];
            
            // 1. 建筑物类型风险
            let buildingTypeScore = 0;
            let buildingTypeWeight = 0.15;
            switch(buildingType) {
                case 'residential': buildingTypeScore = 3; break;
                case 'office': buildingTypeScore = 4; break;
                case 'industrial': buildingTypeScore = 7; break;
                case 'hospital': buildingTypeScore = 8; break;
                case 'school': buildingTypeScore = 6; break;
                case 'cultural': buildingTypeScore = 5; break;
                case 'other': buildingTypeScore = 4; break;
            }
            riskFactors.push({name: "建筑物类型", weight: buildingTypeWeight, score: buildingTypeScore});
            totalScore += buildingTypeScore * buildingTypeWeight;
            
            // 2. 建筑物高度风险
            let heightScore = 0;
            let heightWeight = 0.12;
            if (buildingHeight < 10) heightScore = 2;
            else if (buildingHeight < 20) heightScore = 4;
            else if (buildingHeight < 50) heightScore = 6;
            else heightScore = 8;
            riskFactors.push({name: "建筑物高度", weight: heightWeight, score: heightScore});
            totalScore += heightScore * heightWeight;
            
            // 3. 建筑物面积风险
            let areaScore = 0;
            let areaWeight = 0.1;
            if (buildingArea < 100) areaScore = 2;
            else if (buildingArea < 500) areaScore = 4;
            else if (buildingArea < 2000) areaScore = 6;
            else areaScore = 8;
            riskFactors.push({name: "建筑物面积", weight: areaWeight, score: areaScore});
            totalScore += areaScore * areaWeight;
            
            // 4. 雷暴日数风险
            let lightningScore = 0;
            let lightningWeight = 0.15;
            if (lightningDensity < 15) lightningScore = 2;
            else if (lightningDensity < 30) lightningScore = 4;
            else if (lightningDensity < 60) lightningScore = 6;
            else lightningScore = 8;
            riskFactors.push({name: "雷暴日数", weight: lightningWeight, score: lightningScore});
            totalScore += lightningScore * lightningWeight;
            
            // 5. 地形风险
            let terrainScore = 0;
            let terrainWeight = 0.08;
            switch(terrainType) {
                case 'flat': terrainScore = 3; break;
                case 'hill': terrainScore = 5; break;
                case 'mountain': terrainScore = 7; break;
                case 'water': terrainScore = 6; break;
                case 'urban': terrainScore = 4; break;
            }
            riskFactors.push({name: "地形类型", weight: terrainWeight, score: terrainScore});
            totalScore += terrainScore * terrainWeight;
            
            // 6. 结构材料风险
            let materialScore = 0;
            let materialWeight = 0.05;
            switch(structureMaterial) {
                case 'concrete': materialScore = 3; break;
                case 'steel': materialScore = 6; break;
                case 'wood': materialScore = 8; break;
                case 'brick': materialScore = 4; break;
            }
            riskFactors.push({name: "结构材料", weight: materialWeight, score: materialScore});
            totalScore += materialScore * materialWeight;
            
            // 7. 屋顶材料风险
            let roofScore = 0;
            let roofWeight = 0.07;
            switch(roofMaterial) {
                case 'metal': roofScore = 8; break;
                case 'tile': roofScore = 5; break;
                case 'concrete': roofScore = 3; break;
                case 'asphalt': roofScore = 4; break;
                case 'wood': roofScore = 7; break;
            }
            riskFactors.push({name: "屋顶材料", weight: roofWeight, score: roofScore});
            totalScore += roofScore * roofWeight;
            
            // 8. 避雷针系统
            let rodScore = 0;
            let rodWeight = 0.1;
            rodScore = hasLightningRod === 'yes' ? 1 : 6;
            riskFactors.push({name: "避雷针系统", weight: rodWeight, score: rodScore});
            totalScore += rodScore * rodWeight;
            
            // 9. 电涌保护
            let surgeScore = 0;
            let surgeWeight = 0.08;
            surgeScore = hasSurgeProtection === 'yes' ? 2 : 5;
            riskFactors.push({name: "电涌保护", weight: surgeWeight, score: surgeScore});
            totalScore += surgeScore * surgeWeight;
            
            // 10. 人员密度
            let occupantScore = 0;
            let occupantWeight = 0.05;
            if (occupantDensity < 0.05) occupantScore = 2;
            else if (occupantDensity < 0.1) occupantScore = 4;
            else if (occupantDensity < 0.2) occupantScore = 6;
            else occupantScore = 8;
            riskFactors.push({name: "人员密度", weight: occupantWeight, score: occupantScore});
            totalScore += occupantScore * occupantWeight;
            
            // 11. 易燃材料
            let flammableScore = 0;
            let flammableWeight = 0.03;
            switch(flammableMaterials) {
                case 'none': flammableScore = 1; break;
                case 'low': flammableScore = 3; break;
                case 'medium': flammableScore = 5; break;
                case 'high': flammableScore = 8; break;
            }
            riskFactors.push({name: "易燃材料", weight: flammableWeight, score: flammableScore});
            totalScore += flammableScore * flammableWeight;
            
            // 12. 电子设备
            let equipmentScore = 0;
            let equipmentWeight = 0.02;
            if (electronicEquipment < 10) equipmentScore = 1;
            else if (electronicEquipment < 50) equipmentScore = 3;
            else if (electronicEquipment < 200) equipmentScore = 5;
            else equipmentScore = 7;
            riskFactors.push({name: "电子设备价值", weight: equipmentWeight, score: equipmentScore});
            totalScore += equipmentScore * equipmentWeight;
            
            // 计算最终风险等级 (0-10分制)
            const normalizedScore = (totalScore / 8.0) * 10; // 调整到0-10分范围
            let riskLevel = '';
            let riskClass = '';
            let advice = '';
            
            if (normalizedScore < 3.5) {
                riskLevel = '低风险';
                riskClass = 'low-risk';
                advice = '<p>该建筑物的雷电风险较低，但仍建议采取以下防护措施：</p><ul>' +
                         '<li>定期检查电气系统接地情况</li>' +
                         '<li>确保重要电子设备有基本的电涌保护</li>' +
                         '<li>在雷暴天气时注意关闭非必要电器</li></ul>';
            } else if (normalizedScore < 6.5) {
                riskLevel = '中等风险';
                riskClass = 'medium-risk';
                advice = '<p>该建筑物存在中等雷电风险，建议采取以下防护措施：</p><ul>' +
                         '<li>考虑安装避雷针系统</li>' +
                         '<li>为重要电子设备安装电涌保护器</li>' +
                         '<li>检查并完善建筑物的接地系统</li>' +
                         '<li>制定雷电天气应急预案</li></ul>';
            } else {
                riskLevel = '高风险';
                riskClass = 'high-risk';
                advice = '<p>该建筑物雷电风险较高，强烈建议采取以下防护措施：</p><ul>' +
                         '<li>立即安装完整的避雷针系统</li>' +
                         '<li>为所有重要电路安装多级电涌保护</li>' +
                         '<li>全面检查并改进接地系统</li>' +
                         '<li>对易燃物品采取特殊防护措施</li>' +
                         '<li>制定详细的雷电灾害应急预案</li>' +
                         '<li>考虑购买相关保险</li></ul>';
            }
            
            // 显示结果
            document.getElementById('resultSection').style.display = 'block';
            const riskLevelElement = document.getElementById('riskLevel');
            riskLevelElement.textContent = `风险等级: ${riskLevel} (${normalizedScore.toFixed(1)}/10)`;
            riskLevelElement.className = `risk-level ${riskClass}`;
            
            // 填充风险因素表格
            const tableBody = document.getElementById('riskFactorsTable');
            tableBody.innerHTML = '';
            riskFactors.forEach(factor => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td>${factor.name}</td>
                    <td>${(factor.weight * 100).toFixed(0)}%</td>
                    <td>${factor.score}/10</td>
                `;
                tableBody.appendChild(row);
            });
            
            // 添加总分行
            const totalRow = document.createElement('tr');
            totalRow.innerHTML = `
                <td><strong>总分</strong></td>
                <td>100%</td>
                <td><strong>${normalizedScore.toFixed(1)}/10</strong></td>
            `;
            tableBody.appendChild(totalRow);
            
            // 添加防护建议
            document.getElementById('protectionAdvice').innerHTML = advice;
            
            // 滚动到结果部分
            document.getElementById('resultSection').scrollIntoView({ behavior: 'smooth' });
        }
    </script>
</body>
</html>